<template>
  <div class="home app-container">
    <div class="home-title">
      <div class="col">
        <div class="col-item" v-for="(item,index) in tabs" :key="index">
          <img :src="item.img" alt="">
          <div class="cil-item-content">
            <div style="color: #666666;">{{item.title}}</div>
            <div style="margin-top: 15px;">
              <c-number v-model="item.numb"></c-number>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="home-content" v-loading="loading">
      <div ref="echarts1" class="echarts-line"></div>
    </div>
  </div>
</template>
<script>
  import echarts from 'echarts'
  import CNumber from '@/components/Number'
  import {
    userStatistics
  } from "@/api/menu"
  export default {
    name: 'Home',
    components: {
      CNumber
    },
    data() {
      return {
        loading: false,
        dataTable:{},
        tabs: [{
            img: require('../../../assets/images/home_1.png'),
            numb: 0,
            title: '人员总数 '
          },
          {
            img: require('../../../assets/images/home_2.png'),
            numb: 0,
            title: '授权总数'
          },
          {
            img: require('../../../assets/images/home_3.png'),
            numb: 0,
            title: '餐卡总数'
          },
        ]
      }
    },
    mounted() {
      let myChart1 = echarts.init(this.$refs['echarts1'])
      this.loading = true
      userStatistics().then(res => {
        this.loading = false
        let {
          dimensions,
          source
        } = res
        this.dataTable = res
        this.tabs[0].numb = Number(this.dataTable.personnelSum)
        this.tabs[1].numb = Number(this.dataTable.authorizedPersonnelSum)
        this.tabs[2].numb = Number(this.dataTable.boundPersonnelSum)

        myChart1.setOption({
          tooltip: {
            trigger: 'axis',
            axisPointer: {
              type: 'cross'
            }
          },
          title: {
            text: '多数据柱状图分析工具',
            left: 'center',
            top: '10px',
            textStyle: {
              color: "#FFFFFF",
              fontSize: 30
            }
          },
          legend: {
            top: 70,
            textStyle: {
              color: '#FFFFFF'
            }
          },
          grid: {
            top: 130,
            left: 80,
            right: 80,
            bottom: 50
          },
          dataset: {
            dimensions,
            source
          },
          xAxis: {
            type: 'category',
            axisLine: {
              show: true,
              lineStyle: {
                color: '#ffffff',
                width: 1,
                type: 'solid'
              }
            },
            axisLabel: {
              show: true,
              lineStyle: {
                color: '#ffffff'
              }
            }
          },
          yAxis: {
            axisLine: {
              show: false,
              lineStyle: {
                color: '#ffffff',
                width: 0,
                type: 'solid'
              }
            },
            axisTick: {
              show: false
            },
            axisLabel: {
              show: true,
              lineStyle: {
                color: '#ffffff'
              }
            }
          },
          series: [{
            type: 'bar',
            itemStyle: {
              normal: {
                color: 'rgb(140,212,106)'
              }
            }
          }, {
            type: 'bar',
            itemStyle: {
              normal: {
                color: 'rgb(0,158,253)'
              }
            }
          }, {
            type: 'bar',
            itemStyle: {
              normal: {
                color: 'rgb(255,188,0)'
              }
            }
          }]
        })
      })
    }
  }
</script>
<style lang="scss" scope>
  .home {
    .home-content {
      display: flex;

      .echarts-line {
        width: 1240px;
        height: 500px;
        box-shadow: 0 0 0 2px #f2f2f2;
        border-radius: 4px;

        background-image: linear-gradient(to bottom left, rgb(43, 47, 79), rgb(84, 34, 134));

        &+.echarts-line {
          margin-left: 20px;
        }
      }
    }

    .home-title {
      .col {
        display: flex;
        flex-wrap: wrap;
        width: 1240px;
        margin-bottom: 20px;

        .col-item {
          &+.col-item{
            margin-left: 15px;
          }
          display: flex;
          justify-content: space-between;
          margin-bottom: 20px;
          align-items: center;
          width: 24%;
          height: 113px;
          box-shadow: 0 0 0 2px #f2f2f2;
          border-radius: 4px;
          padding: 0 15px;

          img {
            width: 59px;
          }

          .cil-item-content {
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: flex-end;
          }
        }
      }
    }
  }
</style>
